package com.itbaizhan.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.itbaizhan.domain.AccountInfo;
import com.itbaizhan.feign.TransferLiSi;
import com.itbaizhan.mapper1.AccountInfoMapper;
import com.itbaizhan.service.AccountInfoService;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author 13487
 * @description 针对表【account_info】的数据库操作Service实现
 * @createDate 2024-04-14 14:07:20
 */
@Service
public class AccountInfoServiceImpl extends ServiceImpl<AccountInfoMapper, AccountInfo>
        implements AccountInfoService {

    @Autowired
    private AccountInfoMapper accountInfoMapper;
    @Autowired
    private TransferLiSi transferLiSi;

    @Override
    @GlobalTransactional
    @Transactional
    public void transfer(String accountNo, double amount) {
        QueryWrapper<AccountInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("account_no", accountNo);
        AccountInfo accountInfo = accountInfoMapper.selectOne(queryWrapper);
        if (accountInfo != null && (accountInfo.getAccountBalance() - amount > 0)) {
            accountInfo.setAccountBalance(accountInfo.getAccountBalance() - amount);
            accountInfoMapper.updateById(accountInfo);

            int a = 10 / 0;

            transferLiSi.transfer("2", amount);
        }
    }
}




